package Event;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;


public class EventAdapter {

	private List<ActionEvent> actionEvents;

	public void setActionEvent(ActionEvent actionEvent) {
		if (actionEvents == null) {
			actionEvents = new ArrayList<ActionEvent>();
			actionEvents.add(actionEvent);
		}
	}
	
	public void notifyEvent(EventSource source) {
		for (ActionEvent event : actionEvents) {
			Method[] methods = event.getClass().getDeclaredMethods();
			for (Method method : methods) {
				try {
					method.invoke(event, source);
				} catch (IllegalArgumentException e) {
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
